// import { extend } from 'umi-request';
import type { loginParamsType, loginType} from '@/services/login'

// const request = extend({
//   timeout: 6000,
//   headers: {
//     "clientType": "PC"
//   },
//   errorHandler: function(error) {
//     /* 异常处理 */
//   }
// })
import request from '@/utils/request';


export interface registerParamsType {
  mobile: string;
  code: string;
  password: string;
}

export interface sendParamsType {
  phone: string;
  type: string;
}

export interface posswordParamsType {
  mobile: string;
}

export interface setPosswordParamsType {
  mobile: string;
  psw: string;
  smsCode?: string;
}

export async function fakeAccountLogin(params: loginParamsType | loginType, type: 'cm' | 'bk' | 'ls') {
  let auth = '';
  switch (type) {
    case 'cm':
      auth = 'Basic d29ya2VyX3N1cGVydmlzaW9uX2NvcnA6d29ya2VyX3N1cGVydmlzaW9uX2NvcnBfc2VjcmV0'
      break;
    case 'bk':
      auth = 'Basic YmFua193b3JrZXJfc3VwZXJ2aXNpb246YmFua193b3JrZXJfc3VwZXJ2aXNpb25fc2VjcmV0'
      break;
    case 'ls':
      auth = 'Basic b2Ffd29ya2VyX3N1cGVydmlzaW9uOm9hX3dvcmtlcl9zdXBlcnZpc2lvbl9zZWNyZXQ'
      break;
    default:
      break;
  }
  return request('/login/oauth', {
    method: 'POST',
    data: params,
    requestType: 'form',
    headers:{
      Authorization: auth
    }
  });
}

export async function queryUserCurrent(param: { type: 'cm' | 'bk' | 'ls' }) {
  let url: string = ''
  switch (param.type) {
    case 'cm':
      url = '/api/user/info'
      break;
    case 'bk':
      url = '/bank/user/info'
      break;
    case 'ls':
      url = '/oa/user/info'
      break;
    default:
      break;
  }
  return request(url, {
    method: 'GET'
  });
}

export async function accountRegister(params: registerParamsType) {
  return request('/open/register', {
    method: 'POST',
    data: params,
    requestType: 'form',
    headers:{
      Authorization:'Basic d29ya2VyX3N1cGVydmlzaW9uX2NvcnA6d29ya2VyX3N1cGVydmlzaW9uX2NvcnBfc2VjcmV0'
    }
  })
}

export async function getFakeCaptcha(params: sendParamsType) {
  return request('/oa/sms/send', {
    method: 'POST',
    data: params,
    requestType: 'form'
  })
}

export async function verifyPassword(params: posswordParamsType, type: 'bk' | 'ls' | 'gs') {
  let url: string = ''
  switch (type) {
    case 'bk':
      url = '/bank/user/userPasswordVerify'
      break;
    case 'ls':
      url = '/oa/user/userPasswordVerify'
      break;
    case 'gs':
      url = '/tp/user/userPasswordVerify'
      break;
    default:
      break;
  }
  return request(url, {
    method: 'GET',
    params
  });
}

export async function setPassword(params: setPosswordParamsType, type: 'bk' | 'ls' | 'gs') {
  let url: string = ''
  switch (type) {
    case 'bk':
      url = '/bank/user/changePassword'
      break;
    case 'ls':
      url = '/oa/user/changePassword'
      break;
    case 'gs':
      url = '/tp/user/changePassword'
      break;
    default:
      break;
  }
  return request(url, {
    method: 'POST',
    data: params,
    requestType: 'form'
  })
}

export async function bankApplySubmit(params: any) {
  return request('/open/bank/apply', {
    method: 'POST',
    data: params,
    requestType: 'form'
  })
}